/**
 * @author：anlzou
 * @Date：Created in22:44 2021/4/13
 * @Github：https://github.com/anlzou
 * @Description：
 */
package com.anlzou.bank;

import com.anlzou.dao.InsufficientFundsException;


/**
 * 银行账户的模拟，通过银行卡的号码完成识别，可以进行存钱和取钱的操作。
 */
public class CheckingAccount {
    //balance为余额，number为卡号
    private double balance;
    private int number;

    public CheckingAccount(int number){
        this.number = number;
    }

    //方法：存钱
    public void deposit(double amount){
        balance += amount;
    }

    //方法：取钱
    public void withdraw(double amount) throws InsufficientFundsException {
        if(amount <= balance){
            balance -= amount;
        }else{
            double needs = amount - balance;
            throw new InsufficientFundsException(needs);
        }
    }

    //方法：返回余额
    public double getBalance(){
        return balance;
    }

    //方法：返回卡号
    public int getNumber(){
        return number;
    }
}
